import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { viteMockServe } from 'vite-plugin-mock'

// https://vitejs.dev/config/
export default defineConfig({
  base: './',           // 配置相对路径
  plugins: [vue(),
    viteMockServe({     // 配置mock服务
      mockPath: 'mock'  // mock文件路径
    })
  ],
  resolve: {
    alias: {    // 配置别名
      comp: resolve(__dirname, './src/components'),
      '/icon': './src/assets/image/icon'  // 静态资源别名
    }
  },
  build: {
    minify: 'terser',
    terserOptions: {
      compress: { // 生产环境移除调试信息
        drop_console: true,
        drop_debugger: true
      }
    },
    rollupOptions: {  // 打包输出文件配置
      output: {
        chunkFileNames: 'js/[name]-[hash].js',
        entryFileNames: 'js/[name]-[hash].js',
        assetFileNames: '[ext]/[name]-[hash].[ext]'
      }
    }
  },
  server: {
    proxy: {
      '^/abc': {
        // target: 'http://localhost:5100',
        target: 'https://b.api.jiandanmao.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/abc/, '')
      }
    }
  }
})
